package com.nulldev.util.networking.rudp.impl;

import java.io.Serializable;
import java.util.UUID;

public class Peer implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4639138277556671664L;

	// External port to peer
	public int externalPort;

	// External ip to peer
	public String externalIp;

	// Ping time to peer
	public long ping;

	// A short description or name of the peer
	public String shortName;

	// Longer description of peer
	public String description;

	// Handle the connection
	public UUID connectionID;

	public Peer(int externalPort, String externalIp) {
		this.externalPort = externalPort;
		this.externalIp = externalIp;
	}

	public Peer(int externalPort, String externalIp, long ping, String shortName, String description, UUID connectionID) {
		this.externalPort = externalPort;
		this.externalIp = externalIp;
		this.ping = ping;
		this.shortName = shortName;
		this.description = description;
		this.connectionID = connectionID;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Peer peer = (Peer) o;

		return connectionID != null ? connectionID.equals(peer.connectionID) : peer.connectionID == null;

	}

	@Override
	public int hashCode() {
		return connectionID != null ? connectionID.hashCode() : 0;
	}
}
